package com.yang.designmode.singleton.business;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 日志类
 */
public class Logger3 {
    //实现日志的输出
    private FileWriter fileWriter;

    //实现日志输出
    public Logger3() {
        File file = new File("./log.txt");
        try {
            FileWriter writer = new FileWriter(file, true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 对外输出日志的方法
     * 同步代码块 锁类对象 可以锁住不同线程针对不同对象的锁
     * @param message
     */
    public void log(String message) throws IOException {
        synchronized (Logger3.class){
            fileWriter.write(message);
        }
    }
}
